﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SF.Common;
using System.Collections;
using System.Data;
using System.Configuration;

namespace SF.Web.UI.mallCs
{
    public class goodList
    {
        public string loaddingUsing(Model.sf_user_info userInfo, string templateType)
        {
            string usingMsg = "";
            if (userInfo != null)
            {
                if (templateType == "weishangred")
                {
                    usingMsg = "<link rel='stylesheet' type='text/css' href='css/goodList.css' media='all' />";
                }
                else if (templateType == "weishanggreen")
                {
                    usingMsg = "<link rel='stylesheet' type='text/css' href='css/goodListgreen.css' media='all' />";
                }
                else if (templateType == "syj")
                {
                    usingMsg = "<link rel=\"stylesheet\" type=\"text/css\" href=\"/mall/css/goodlistsyj.css\" media=\"all\">";
                }
            }
            return usingMsg;
        }
        public string loaddingJs(Model.sf_user_info userInfo, string templateType)
        {
            string jsMsg = "";
            if (userInfo != null)
            {
                if (templateType == "weishangred" || templateType == "weishanggreen")
                {
                    jsMsg = "";
                }
                else if (templateType == "syj")
                {
                    jsMsg = @"function showShareGuide() {
                                  $('#js-share-guide').removeClass('hide');
                              }
                              $(function () {
                                  $('#js-share-guide').click(function () {
                                      $('#js-share-guide').addClass('hide');
                                  });
                              });";
                }
            }
            return jsMsg;
        }
        public string loaddingHtml(Model.sf_user_info userInfo, string parm1, string parm2, string templateType)
        {
            string htmlMsg = "", appWhere="";
            if (userInfo != null)
            {
                appWhere = Utils.getWhereByInfo(userInfo.busnieseNum, userInfo.appNum, userInfo.templatesNum);
                if (templateType == "weishangred" || templateType == "weishanggreen")
                {
                    #region weishangred || weishanggreen

                    BLL.sf_goods_info goodsBll = new BLL.sf_goods_info();
                    BLL.sf_goods_types typeBll = new BLL.sf_goods_types();
                    BLL.sf_goods_amounts amountBll = new BLL.sf_goods_amounts();
                    int id = Convert.ToInt32(parm1);
                    int ishot = Convert.ToInt32(parm2);
                    Model.sf_goods_types type = typeBll.GetModel(id);
                    string searchGoods = "", title = "商品列表";
                    if (ishot > 0)
                    {
                        title = ishot == 1 ? "新品上架" : ishot == 2 ? "精选商品" : "特惠商品";
                        DataSet ds = goodsBll.GetList("ishot=" + ishot + " and status=1 and " + appWhere + " order by sort");
                        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                        {
                            if (amountBll.Exists("goodsNum='" + ds.Tables[0].Rows[i]["goodsNum"] + "' and " + appWhere) || Convert.ToInt32(ds.Tables[0].Rows[i]["num"])>0)
                            {
                                searchGoods += "<div class='jx_g'><div class='jx_g_img'><a href='detailed.aspx?id=" + ds.Tables[0].Rows[i]["id"] + "' class='J_bi_product_item J_ytag' data-dap='' data-pid='561592'><img class='' src='" + ds.Tables[0].Rows[i]["showImgs"] + "'></a></div>";
                                searchGoods += "<div class='jx_g_info'><p class='jx_g_title'><a href='' class='J_bi_product_item J_ytag' data-dap='' data-pid='561592'>" + ds.Tables[0].Rows[i]["names"] + "</a></p>";
                                if (ds.Tables[0].Rows[i]["goodsTypeNum"].ToString() == "maquillage")
                                {
                                    searchGoods += "<p class='jx_g_price'><span class='jx_g_price_wx'>统一零售价<span><i>￥</i>" + ds.Tables[0].Rows[i]["salesPrice"] + "</span></span></p><a href='detailed.aspx?id=" + ds.Tables[0].Rows[i]["id"] + "' class='WX_btn jx_g_btn J_bi_product_item J_ytag' data-dap='' data-pid='561592'>立即购买</a></div></div>";
                                }
                                else
                                {
                                    searchGoods += "<p class='jx_g_price'><span class='jx_g_price_wx'>惊爆价<span><i>￥</i>" + ds.Tables[0].Rows[i]["salesPrice"] + "</span></span><del class=‘jx_g_price_market’>￥" + ds.Tables[0].Rows[i]["showPrice"] + "</del></p><a href='detailed.aspx?id=" + ds.Tables[0].Rows[i]["id"] + "' class='WX_btn jx_g_btn J_bi_product_item J_ytag' data-dap='' data-pid='561592'>立即购买</a></div></div>";
                                }
                            }
                        }
                    }
                    else
                    {
                        title = "所有商品";
                        string strWhere = " status=1 and " + appWhere;
                        if (type != null)
                        {
                            title = type.name;
                            string typeNums = typeBll.GetTypeNameById(type, appWhere);
                            strWhere = " (typeNum='" + (typeNums.Substring(0, typeNums.Length - 1)).Replace(",", "' or typeNum='") + "') and status=1 and " + appWhere + " order by sort";
                        }
                        DataSet ds = goodsBll.GetList(strWhere);
                        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                        {
                            searchGoods += "<div class='jx_g'><div class='jx_g_img'><a href='detailed.aspx?id=" + ds.Tables[0].Rows[i]["id"] + "' class='J_bi_product_item J_ytag' data-dap='' data-pid='561592'><img class='' src='" + ds.Tables[0].Rows[i]["showImgs"] + "'></a></div>";
                            searchGoods += "<div class='jx_g_info'><p class='jx_g_title'><a href='' class='J_bi_product_item J_ytag' data-dap='' data-pid='561592'>" + ds.Tables[0].Rows[i]["names"] + "</a></p>";
                            if (ds.Tables[0].Rows[i]["goodsTypeNum"].ToString() == "maquillage")
                            {
                                searchGoods += "<p class='jx_g_price'><span class='jx_g_price_wx'>统一零售价<span><i>￥</i>" + ds.Tables[0].Rows[i]["salesPrice"] + "</span></span></p><a href='detailed.aspx?id=" + ds.Tables[0].Rows[i]["id"] + "' class='WX_btn jx_g_btn J_bi_product_item J_ytag' data-dap='' data-pid='561592'>立即购买</a></div></div>";
                            }
                            else
                            {
                                searchGoods += "<p class='jx_g_price'><span class='jx_g_price_wx'>惊爆价<span><i>￥</i>" + ds.Tables[0].Rows[i]["salesPrice"] + "</span></span><del class=‘jx_g_price_market’>￥" + ds.Tables[0].Rows[i]["showPrice"] + "</del></p><a href='detailed.aspx?id=" + ds.Tables[0].Rows[i]["id"] + "' class='WX_btn jx_g_btn J_bi_product_item J_ytag' data-dap='' data-pid='561592'>立即购买</a></div></div>";
                            }
                        }
                    }
                    if (string.IsNullOrEmpty(searchGoods))
                    {
                        searchGoods = "<div class='jx_g_info'><p class='jx_g_title' style='margin-top:20px;'>此类商品正在进行上架中，请耐心等待！</p></div>";
                    }
                    htmlMsg = "<body><section class='main_title' style='' id='top2'><h2 id='topname'><label id='lblListTitle'>" + title + "</label></asp:Label></h2><a href='javascript:window.history.go(-1);' data-type='back' class='go-back' ><span class='icons fa fa-angle-left' data-icon=''></span></a></section><div class='h30' id='h30' style=''></div><div class='WX_con' id='J_main'><div class='jx'><div class='jx_list'>" + searchGoods + "</div></div></div><div class='h50'></div><div class='fixed bottom'><dl class='sub-nav nav-b3'><dd class='active'><a href='javascript:void(0)'><i class='icon-store'></i>逛商城</a></dd><dd><a href='../mall/cart.aspx'><i class='icon-distribusion'></i>购物车</a></dd><dd><a href='../mall/user.aspx'><i class='icon-member'></i>会员中心</a></dd></dl></div></body>";

                    #endregion
                }
                else if (templateType == "syj")
                {
                    #region syj 模板

                    string title = "所有商品";
                    string strWhere = " status=1 and " + appWhere;

                    int id = Convert.ToInt32(parm1);
                    int ishot = Convert.ToInt32(parm2);
                    BLL.sf_goods_info goodsBll = new BLL.sf_goods_info();
                    BLL.sf_goods_types typeBll = new BLL.sf_goods_types();
                    Model.sf_goods_types type = typeBll.GetModel(id);
                    if (type != null)
                    {
                        title = type.name;
                        string typeNums = typeBll.GetTypeNameById(type, appWhere);
                        strWhere = " (typeNum='" + (typeNums.Substring(0, typeNums.Length - 1)).Replace(",", "' or typeNum='") + "') and status=1 and " + appWhere + " order by sort";
                    }
                    else 
                    {
                        title = ishot == 1 ? "新品上架" : ishot == 2 ? "精选商品" : "特惠商品";
                    }
                    DataSet ds = goodsBll.GetList(strWhere);
                    

                    //页面结构
                    StringBuilder sbBody = new StringBuilder();//页面主体
                    sbBody.AppendLine("<body class='body-fixed-bottom'>");


                    //页面主体部分
                    sbBody.AppendLine("    <!-- 页面主体 -->");
                    sbBody.AppendLine("    <div style='min-height: 641px;' class='container '>");
                    sbBody.AppendLine("        <div class='content '>");
                    sbBody.AppendLine("            <div class='content-body js-page-content' data-page-position='tag-kkld2okt'>");

                    //标题
                    sbBody.AppendLine("                <!-- 标题 -->");
                    sbBody.AppendLine("                <div class='custom-title'>");
                    sbBody.AppendLine("                    <h2 class='title'>" + title + "</h2>");
                    sbBody.AppendLine("                </div>");

                    sbBody.AppendLine("                <!-- 富文本内容区域 -->");
                    sbBody.AppendLine("                <ul class='js-goods-list sc-goods-list pic clearfix size-2' data-size='2' data-showtype='card' style='visibility: visible;'>");
                    sbBody.AppendLine("                    <!-- 商品区域 -->");
                    sbBody.AppendLine("                    <!-- 展现类型判断 -->");

                    //商品列表
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        string styleClass = (i) % 3 == 0 ? "big-pic" : "small-pic";
                        string styleHeight = (i) % 3 == 0 ? "height: 346px;" : "";

                        string goodsName = ds.Tables[0].Rows[i]["names"].ToString();
                        string goodsId = ds.Tables[0].Rows[i]["id"].ToString();
                        string goodsImgUrl = ds.Tables[0].Rows[i]["showImgs"].ToString();
                        string goodsSalesPrice = ds.Tables[0].Rows[i]["salesPrice"].ToString();

                        sbBody.AppendLine("                    <li class='js-goods-card goods-card " + styleClass + " card'>");
                        sbBody.AppendLine("                        <a href='detailed.aspx?id=" + goodsId + "' class='js-goods link clearfix' target='_top' data-goods-id='" + goodsId + "' title='" + goodsName + "'>");
                        sbBody.AppendLine("                            <div style='" + styleHeight + " background-color: rgb(255, 255, 255);' class='photo-block' data-width='800' data-height='800'>");
                        sbBody.AppendLine("                                <img src='" + goodsImgUrl + "' style='display: inline;' class='goods-photo js-goods-lazy' data-src='" + goodsImgUrl + "'>");
                        sbBody.AppendLine("                            </div>");
                        sbBody.AppendLine("                            <div class='info clearfix info-no-title info-price btn4'>");
                        sbBody.AppendLine("                                <p class=' goods-title '>" + goodsName + "</p>");
                        sbBody.AppendLine("                                <p class='goods-sub-title c-black hide'></p>");
                        sbBody.AppendLine("                                <p class='goods-price'>");
                        sbBody.AppendLine("                                    <em>￥" + goodsSalesPrice + "</em>");
                        sbBody.AppendLine("                                </p>");
                        sbBody.AppendLine("                                <p class='goods-price-taobao  hide'></p>");
                        sbBody.AppendLine("                            </div>");
                        sbBody.AppendLine("                            <div class='goods-buy btn4 info-no-title'></div>");
                        sbBody.AppendLine("                            <div class='js-goods-buy buy-response' data-alias='f84ba13t' data-postage='0' data-buyway='1' data-id='"+goodsId+"' data-title='" + goodsName + "' data-price='" + goodsSalesPrice + "' data-isvirtual='0'></div>");
                        sbBody.AppendLine("                        </a>");
                        sbBody.AppendLine("                    </li>");
                    }

                    sbBody.AppendLine("                </ul>");
                    sbBody.AppendLine("            </div>");
                    

                    //商城菜单
                    //页面固定菜单内容
                    sbBody.AppendLine("            <!--固定菜单-->");
                    sbBody.AppendLine("                <div style='display: block;' id='shop-nav'>");
                    sbBody.AppendLine("                    <div class='js-navmenu js-footer-auto-ele shop-nav nav-menu nav-menu-1 has-menu-3'>");
                    sbBody.AppendLine("                        <div class='nav-special-item nav-item'>");
                    sbBody.AppendLine("                            <a href='index.aspx?appnum=" + userInfo.appNum + "' class='home'>");
                    sbBody.AppendLine("                                主页");
                    sbBody.AppendLine("                            </a>");
                    sbBody.AppendLine("                        </div>");
                    sbBody.AppendLine("                        <div class='nav-item'>");
                    sbBody.AppendLine("                            <a class='mainmenu js-mainmenu' href='/mall/cart.aspx'>");
                    sbBody.AppendLine("                                <i class='arrow-weixin'>");
                    sbBody.AppendLine("                                </i>");
                    sbBody.AppendLine("                                <span class='mainmenu-txt'>");
                    sbBody.AppendLine("                                    购物车");
                    sbBody.AppendLine("                                </span>");
                    sbBody.AppendLine("                            </a>");
                    sbBody.AppendLine("                        </div>");
                    sbBody.AppendLine("                        <div class='nav-item'>");
                    sbBody.AppendLine("                            <a class='mainmenu js-mainmenu' href='/mall/user.aspx'>");
                    sbBody.AppendLine("                                <i class='arrow-weixin'>");
                    sbBody.AppendLine("                                </i>");
                    sbBody.AppendLine("                                <span class='mainmenu-txt'>");
                    sbBody.AppendLine("                                    会员中心");
                    sbBody.AppendLine("                                </span>");
                    sbBody.AppendLine("                            </a>");
                    sbBody.AppendLine("                            <!-- 子菜单 -->");
                    sbBody.AppendLine("                            <div class='submenu js-submenu'>");
                    sbBody.AppendLine("                                <span class='arrow before-arrow'>");
                    sbBody.AppendLine("                                </span>");
                    sbBody.AppendLine("                                <span class='arrow after-arrow'>");
                    sbBody.AppendLine("                                </span>");
                    sbBody.AppendLine("                                <ul>");
                    sbBody.AppendLine("                                    <li>");
                    sbBody.AppendLine("                                        <a href='http://wap.koudaitong.com/v2/feature/6n8o0l1b'>");
                    sbBody.AppendLine("                                            积分兑换");
                    sbBody.AppendLine("                                        </a>");
                    sbBody.AppendLine("                                    </li>");
                    sbBody.AppendLine("                                </ul>");
                    sbBody.AppendLine("                            </div>");
                    sbBody.AppendLine("                        </div>");
                    sbBody.AppendLine("                    </div>");
                    sbBody.AppendLine("                </div>");
                    sbBody.AppendLine("            </div>");
                    sbBody.AppendLine("        </div>");
                    sbBody.AppendLine(""); 
                     
                    //页脚内容
                    sbBody.AppendLine("        <div class='js-footer' style='min-height: 1px;'>");
                    sbBody.AppendLine("            <div>");
                    sbBody.AppendLine("                <div class='footer'>");
                    sbBody.AppendLine("                    <div class='copyright'>");
                    sbBody.AppendLine("                        <div class='ft-links'>");
                    sbBody.AppendLine("                            <a href='index.aspx?appnum="+userInfo.appNum+"' target='_top'>");
                    sbBody.AppendLine("                                店铺主页");
                    sbBody.AppendLine("                            </a>");
                    sbBody.AppendLine("                            <a href='user.aspx'");
                    sbBody.AppendLine("                            target='_top'>");
                    sbBody.AppendLine("                                会员中心");
                    sbBody.AppendLine("                            </a>");
                    sbBody.AppendLine("                            <a href='javascript:showShareGuide();' class='js-open-follow'>");
                    sbBody.AppendLine("                                关注我们");
                    sbBody.AppendLine("                            </a>");
                    sbBody.AppendLine("                        </div>");
                    sbBody.AppendLine("                        <div class='ft-copyright'>");
                    sbBody.AppendLine("                            <a href='/door/index.aspx' target='_top'>");
                    sbBody.AppendLine("                                微信提供技术支持");
                    sbBody.AppendLine("                            </a>");
                    sbBody.AppendLine("                        </div>");
                    sbBody.AppendLine("                    </div>");
                    sbBody.AppendLine("                </div>");
                    sbBody.AppendLine("            </div>");
                    sbBody.AppendLine("        </div>");
                    sbBody.AppendLine("");

                    string qrcodeuri = "/allqrcode/code/"+userInfo.inviteKey+".jpg";
                    sbBody.AppendLine("          <div id='js-share-guide' class='js-fullguide fullscreen-guide hide' style='font-size: 20px; line-height: 30px; color: #fff; text-align: center;'>");
                    sbBody.AppendLine("            <span class='js-close-guide guide-close'>&times;</span>");
                    sbBody.AppendLine("            <div class='guide-inner'>");
                    sbBody.AppendLine("                通过微信【扫一扫】功能");
                    sbBody.AppendLine("                <br />扫描二维码关注我们");
                    sbBody.AppendLine("                <img style='width:160px; height: 160px;margin-top: 20px;' src='" + qrcodeuri + "' />");
                    sbBody.AppendLine("            </div>");
                    sbBody.AppendLine("         </div>");

                    //搜索条
                    //sbBody.AppendLine("    <!-- 搜索条 -->");
                    //sbBody.AppendLine("    <div class='search-bar' style='display:none;'>");
                    //sbBody.AppendLine("        <form class='search-form' action='http://wap.koudaitong.com/v2/search' method='GET'>");
                    //sbBody.AppendLine("            <input class='search-input' placeholder='搜索本店所有商品' name='q' value='' type='search'>");
                    //sbBody.AppendLine("            <input name='kdt_id' value='384' type='hidden'><a class='js-search-cancel search-cancel' href='javascript:;'>取消</a>");
                    //sbBody.AppendLine("            <span class='search-icon'>");
                    //sbBody.AppendLine("            </span>");
                    //sbBody.AppendLine("            <span class='close-icon hide'>");
                    //sbBody.AppendLine("            </span>");
                    //sbBody.AppendLine("        </form>");
                    //sbBody.AppendLine("        <div class='history-wrap center'>");
                    //sbBody.AppendLine("            <ul class='history-list search-recom-list js-history-list clearfix'></ul>");
                    //sbBody.AppendLine("            <a class='tag tag-clear js-tag-clear c-gray-darker hide' href='javascript:;'>清除历史搜索</a>");
                    //sbBody.AppendLine("        </div>");
                    //sbBody.AppendLine("    </div>");


                    //页面工具
                    //sbBody.AppendLine("<!-- 页面工具 -->");
                    //sbBody.AppendLine("    <div id='right-icon' class='js-right-icon no-text'>");
                    //sbBody.AppendLine("	    <div style='width: 50px;' class='js-right-icon-container right-icon-container clearfix'>");
                    //sbBody.AppendLine("            <a id='global-cart' href='http://wap.koudaitong.com/v2/trade/cart?kdt_id=384' class='icon hide s0' style=''>");
                    //sbBody.AppendLine("                <p class='icon-img'></p>");
                    //sbBody.AppendLine("                <p class='icon-txt'>购物车</p>");
                    //sbBody.AppendLine("            </a>");
                    //sbBody.AppendLine("            <a id='global-wish' href='http://trade.koudaitong.com/wxpay/wish?kdt_id=384' class='icon'>");
                    //sbBody.AppendLine("                <p class='icon-img'></p>");
                    //sbBody.AppendLine("                <p class='icon-txt'>心愿单</p>");
                    //sbBody.AppendLine("            </a>");
                    //sbBody.AppendLine("	        <a class='js-show-more-btn icon show-more-btn hide'></a>");
                    //sbBody.AppendLine("	    </div>");
                    //sbBody.AppendLine("    </div>");

                    sbBody.AppendLine("</body>");


                    htmlMsg = sbBody.ToString(); 

                    #endregion
                }
            }
            return htmlMsg;
        }
    }
}
